<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of View
 *
 * @author Marek S
 */
class View {
    protected $fileName;
    protected $varHolder;
    
    public function __construct(){
        $this->varHolder = array();
        $this->fileName = null;
    }
    
    public function setFile($file){
        $this->fileName = $file;
    }
    
    public function addVar($name, $value){
        $this->varHolder[$name] = $value;
    }
    
    public function getVar($name){
        return $this->varHolder[$name];
    }

    public function isExists(){
        return file_exists(Application::getInstance()->getMainApplicationDirectory() . '/view/' . $this->fileName);
    }
    
    public function __toString() {
        $content = '';
        ob_start();
        foreach ($this->varHolder as $key => $var){
            $$key = $var;
        }
        include(Application::getInstance()->getMainApplicationDirectory() . '/view/' . $this->fileName);
        $content = ob_get_contents();
        ob_end_clean();
        return $content;
    }
}
